#coding:utf-8
import os
import ConfigParser
import platform
root_dir = os.getcwd()
class Config():
    def __init__(self):
        pass

    #获取程序根目录
    def get_home_dir(self):
        #print root_dir
        conf = ConfigParser.ConfigParser()
        #conf.read("/home/yzfu/nlp/kg_abc/fyz_kg_nlp/abc_kg_nlp/config/gol.cfg")
        conf.read(root_dir+"/config/gol.cfg")
        if platform.system()=="Windows" :
            home_dir = conf.get("gol", "home_dir")
        else:
            home_dir = conf.get("gol", "home_dir_linux")
        #print home_dir
        return home_dir

    #获取mysql连接
    def get_mysql_conn(self):
        conf = ConfigParser.ConfigParser()
        conf.read("/home/yzfu/nlp/kg_abc/fyz_kg_nlp/abc_kg_nlp/config/gol.cfg")
        #conf.read(root_dir+"/config/gol.cfg")
        host = conf.get("mysql", "host")
        port = conf.get("mysql", "port")
        dbname = conf.get("mysql", "dbname")
        user_name = conf.get("mysql", "user_name")
        password = conf.get("mysql", "password")
        return host,port,dbname,user_name,password

    #获取mongodb的连接
    def get_mongodb_conn(self):
        conf = ConfigParser.ConfigParser()
        conf.read(root_dir+"/config/gol.cfg")
        dsn = conf.get('mongodb','dsn')
        return dsn

    def get_mysql_test(self):
        conf = ConfigParser.ConfigParser()
        #print root_dir
        conf.read("/home/yzfu/nlp/kg_abc/fyz_kg_nlp/abc_kg_nlp/config/gol.cfg")
        host = conf.get("mysql_test", "host")
        port = conf.get("mysql_test", "port")
        dbname = conf.get("mysql_test", "dbname")
        user_name = conf.get("mysql_test", "user_name")
        password = conf.get("mysql_test", "password")
        return host, port, dbname, user_name, password
    #获取程序根目录
    def get_home_data_dir(self):
        conf = ConfigParser.ConfigParser()
        #conf.read("/home/yzfu/nlp/kg_abc/fyz_kg_nlp/abc_kg_nlp/config/gol.cfg")
        conf.read(root_dir+"/config/gol.cfg")
        if platform.system()=="Windows" :
            home_dir = conf.get("gol", "home_data_dir")
        else:
            home_dir = conf.get("gol", "home_data_dir")
        #print home_dir
        return home_dir

if __name__ == "__main__":
    config = Config()
    config.get_home_dir()

